package cn.wolfcode.qo;

import cn.wolfcode.domain.Department;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.List;
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class PageResult<T> {
    private int currentPage=1;
    private int pageSize=3;

    private int totalCount;
    private List<T> listData;

    private int prevPage;
    private int nextPage;
    private int totalPage;

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> listData) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.listData = listData;

        //当查询总的条数小于等于每页显示数据
        if(this.totalCount<=this.pageSize){
            this.totalPage=1;
            this.nextPage=1;
            this.currentPage=1;
            return;
        }


        this.prevPage = currentPage - 1 >= 1 ? currentPage - 1 : currentPage;
        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;

        this.nextPage = currentPage + 1 <= this.totalPage ? currentPage + 1 : this.totalPage;
    }
}
